<?php
/**
* @Copyright Copyright (C) 2011 - xml/swf
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/
/** ensure this file is being included by a parent file */
defined( '_JEXEC' ) or die( 'Restricted access' ); 
require_once (dirname(__FILE__).DS.'noimage_functions.php');


$bannerWidth                   = intval($params->get( 'bannerWidth', 720 ));
$imagewidth                   = intval($params->get( 'imagewidth', 516 ));
$imageheight                   = intval($params->get( 'imageheight', 397 ));
$bannerHeight                  = intval($params->get( 'bannerHeight', 460 ));
$backgroundColor         = trim($params->get( 'backgroundColor', '#ffffff' ));
$wmode                 = trim($params->get( 'wmode', 'opaque' )); 
$baseColor                   = $params->get( 'baseColor', '0x92BB38' );
$thumbwidth                   = intval($params->get( 'thumbwidth', 170 ));
$thumbheight                   = intval($params->get( 'thumbheight', 115 ));

$xml_fname                 = trim($params->get( 'xml_fname', 'a' ));
$catppv_id = 'xml/' . $xml_fname;

$module_path = dirname(__FILE__).DS;
if (!is_dir($module_path . 'xml/')) {
	@mkdir($module_path . 'xml/', 0777);
}

if (!function_exists('create_jslidepro_files')) {
function create_jslidepro_files($params, &$catppv_id)
{
$caption        = trim($params->get('caption', '' )); 
$caption_arr    = explode("\n",$caption);
$thumbs        = trim($params->get('thumbs', '' )); 
$thumbs_arr    = explode("\n",$thumbs);
$pic        = trim($params->get('pic', '' )); 
$pic_arr    = explode("\n",$pic);
$imgdsc        = trim($params->get('imgdsc', '' ));
$imgdsc_arr    = explode("\n",$imgdsc);
$links        = trim($params->get('links', '' )); 
$links_arr    = explode("\n",$links);

	
	$xml_category_data = '<?xml version="1.0" encoding="iso-8859-1"?>

<slideshow >
		<baseDef showPlay="'.trim($params->get( 'showPlay', '0')).'" autoSlideTimer="'.intval($params->get( 'autoSlideTimer', '5')).'"  autoScale="'.trim($params->get( 'autoScale', '0')).'" autoAlign="'.trim($params->get( 'autoAlign', '0')).'" gradientColor1="'.trim($params->get( 'gradientColor1', '0xBFBFBF')).'"  gradientColor2="'.trim($params->get( 'gradientColor2', '0xE7E7E7')).'" pictureBoxColor= "'.trim($params->get( 'pictureBoxColor', '0x666666')).'" PictureThumbTitleColor="'.trim($params->get( 'PictureThumbTitleColor', '0xFFFFFF')).'" TextColor="'.trim($params->get( 'TextColor', '0xFFFFFF')).'" TitleTextColor="'.trim($params->get( 'TitleTextColor', '0x00CC33')).'" transitionTime="'.trim($params->get( 'transitionTime', '1')).'" TextSize="'.trim($params->get( 'TextSize', '10')).'" ThumbTextSize="'.trim($params->get( 'ThumbTextSize', '11')).'" />
';

////////// start : noimage code //////////////

$exist_url = JURI::root();
$server_path = getCurUrl($exist_url);
$hasAccess = _isHavingAccess();

//////////////////////////////////////////



	foreach ($pic_arr as $curr_k=>$curr_pic) {
	$xml_category_data .= '
		<pic url="'.trim($links_arr[$curr_k]).'" target="'.trim($params->get( 'target', '2')).'" ';

		
		


if($hasAccess =='2'){

/////////////// Thumb Image
	
	$resCode_thumb = getResCode(trim($server_path.$thumbs_arr[$curr_k]));
	$is_imageurl_thumb = substr_count($resCode_thumb['content_type'], 'image');

	if($is_imageurl_thumb > 0)
	{
		if($resCode_thumb['http_code']=='200'){

			$xml_category_data .= '	thumb="'.trim($server_path.$thumbs_arr[$curr_k]).'" ';

		}else{
$xml_category_data .= '	thumb="'.$server_path.'modules/mod_slideshowpro/models/thumb/noimage_thumb.png" ';

		}
	}else{
			$xml_category_data .= '	thumb="'.$server_path.'modules/mod_slideshowpro/models/thumb/noimage_thumb.png" ';

	}


///// Main Image
    $resCode = getResCode(trim($server_path.$pic_arr[$curr_k]));

	$is_imageurl = substr_count($resCode['content_type'], 'image');
	if($is_imageurl > 0)
	{
		if($resCode['http_code']=='200'){

			$xml_category_data .= 'pic="'.trim($server_path.$pic_arr[$curr_k]).'">';

		}else{

			$xml_category_data .= 'pic="'.$server_path.'modules/mod_slideshowpro/models/no_image.png">';

		}
	}else{
			$xml_category_data .= 'pic="'.$server_path.'modules/mod_slideshowpro/models/no_image.png">';

	}



}

else if($hasAccess =='1')
	{


////// Thumb Image

$urlIsImage = isImage(trim($server_path.$thumbs_arr[$curr_k]));
		
		if($urlIsImage=='1'){

			$fileExist = http_file_exists(trim($server_path. $thumbs_arr[$curr_k]));
			
			if($fileExist =='1'){
			$xml_category_data .= '	thumb="'.trim($server_path.$thumbs_arr[$curr_k]).'" '; 
			
			}else{

			$xml_category_data .= '	thumb="'.$server_path.'modules/mod_slideshowpro/models/thumb/noimage_thumb.png" ';
			
			}
		
		}else{
			$xml_category_data .= '	thumb="'.$server_path.'modules/mod_slideshowpro/models/thumb/noimage_thumb.png" '; 

		}

		//// Main Image
        $urlIsImage = isImage(trim($server_path.$pic_arr[$curr_k]));
		
		if($urlIsImage=='1'){

			$fileExist = http_file_exists(trim($server_path.$pic_arr[$curr_k]));
			
			if($fileExist =='1'){

			$xml_category_data .= 'pic="'.trim($server_path.$pic_arr[$curr_k]).'">';

			}else{

			$xml_category_data .= 'pic="'.$server_path.'modules/mod_slideshowpro/models/no_image.png">';
			
			}
		
		}else{
			$xml_category_data .= 'pic="'.$server_path.'modules/mod_slideshowpro/models/no_image.png">';
		}

	}else{

		$xml_category_data .= '	thumb="'.trim($server_path.$thumbs_arr[$curr_k]).'" ';
		
		$xml_category_data .= ' pic="'.trim($server_path.$pic_arr[$curr_k]).'"> ';
	}

/////////////////// END ////////////////////////////


			
	$xml_category_data .= '	<Title><![CDATA['.trim($caption_arr[$curr_k]).']]></Title><desc><![CDATA['.trim($imgdsc_arr[$curr_k]).']]></desc></pic>
	';
	}
	$xml_category_data .= "
	</slideshow>";
	
	$module_path = dirname(__FILE__).DS;
	
	$catppv_id .= md5($xml_category_data);

	if (!file_exists($module_path . $catppv_id . '.swf')) {
		copy($module_path . 'slideshow.swf', $module_path . $catppv_id . '.swf');

///////// set chmod 0644 for creating .swf file  if server is not windows
	$os_string = php_uname('s');
	$cnt = substr_count($os_string, 'Windows');
	if($cnt ==0){
		@chmod($module_path . $catppv_id . '.swf', 0644);
	}

	}
	
	$xml_categories_filename = $module_path.$catppv_id.'.xml';
	if (!file_exists($xml_categories_filename)) {
		$xml_categories_file = fopen($xml_categories_filename,'w');
		fwrite($xml_categories_file, $xml_category_data);

///////// set chmod 0777 for creating .xml file  if server is not windows
	$os_string = php_uname('s');
	$cnt = substr_count($os_string, 'Windows');
	if($cnt ==0){
		@chmod($xml_categories_filename, 0777);
	}

		fclose($xml_categories_file);
	}

}
}

create_jslidepro_files($params, $catppv_id);
$exist_url = JURI::root();
$server_path = getCurUrl($exist_url);
?>

<div align="center">

<script type="text/javascript">AC_FL_RunContent = 0;</script>
<script src="<?php echo $server_path?>modules/mod_slideshowpro/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript">

	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '<?php echo $bannerWidth;?>',
			'height', '<?php echo $bannerHeight; ?>',
			'src', '<?php echo $server_path?>modules/mod_slideshowpro/<?php echo $catppv_id; ?>',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', '<?php echo $wmode;?>',
			'devicefont', 'false',
			'id', 'slpro<?php echo $xml_fname; ?>',
			'bgcolor', '<?php echo $backgroundColor; ?>',
			'name', 'slpro<?php echo $xml_fname; ?>',
			'menu', 'true',
			'allowFullScreen', 'true',
			'allowScriptAccess','sameDomain',
			'movie', '<?php echo $server_path?>modules/mod_slideshowpro/<?php echo $catppv_id; ?>',
			'salign', '',
			'FlashVars','maxwidth=<?php echo $bannerWidth;?>&amp;maxheight=<?php echo $bannerHeight; ?>&amp;imagewidth=<?php echo $imagewidth;?>&amp;imageheight=<?php echo $imageheight;?>&amp;baseColor=<?php echo $baseColor;?>&amp;thumbwidth=<?php echo $thumbwidth;?>&amp;thumbheight=<?php echo $thumbheight;?>&amp;xmlfileurl=<?php echo $server_path?>modules/mod_slideshowpro/<?php echo $catppv_id; ?>.xml'
			); //end AC code
	}

</script>

<noscript>

<object data="<?php echo $server_path.'modules/mod_slideshowpro/'.$catppv_id.'.swf';?>"  type="application/x-shockwave-flash" width="<?php echo $bannerWidth;?>" height="<?php echo $bannerHeight; ?>" align="middle"  id="slpro<?php echo $xml_fname; ?>">
<param name="allowScriptAccess" value="sameDomain" />
<param name="wmode" value="<?php echo $wmode;?>" />

<param name="FlashVars" value="maxwidth=<?php echo $bannerWidth;?>&amp;maxheight=<?php echo $bannerHeight; ?>&amp;imagewidth=<?php echo $imagewidth;?>&amp;imageheight=<?php echo $imageheight;?>&amp;baseColor=<?php echo $baseColor;?>&amp;thumbwidth=<?php echo $thumbwidth;?>&amp;thumbheight=<?php echo $thumbheight;?>&amp;xmlfileurl=<?php echo $server_path?>modules/mod_slideshowpro/<?php echo $catppv_id; ?>.xml"/>

<param name="allowFullScreen" value="true" />	
<param name="movie" value="<?php echo $server_path.'modules/mod_slideshowpro/'.$catppv_id.'.swf';?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="<?php echo $backgroundColor; ?>" />

</object>


</noscript>
</div>